<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" style="background-color: #f2f2f2;">
<head>
    <meta charset="UTF-8"/>
    <title>学生信息导入</title>

    <link rel="stylesheet" type="text/css" th:href="@{/css/bootstrap.min.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/plugin/easyui/themes/default/easyui.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/plugin/easyui/themes/icon.css}">

    <link rel="stylesheet" type="text/css"  th:href="@{/css/style_index.css}">
    <link rel="stylesheet" type="text/css"  th:href="@{/css/style_table.css}">
    <link rel="stylesheet" type="text/css"  th:href="@{/plugin/layui/css/layui.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/css/addressResourcePutIn.css}">
    <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
    <script type="text/javascript"  th:src="@{/js/util.js}"></script>
    <script type="text/javascript" th:src="@{/plugin/easyui/jquery.easyui.min.js}"></script>
    <script type="text/javascript" th:src="@{/plugin/easyui/easyui-lang-zh_CN.js}"></script>
    <script type="text/javascript" th:src="@{/plugin/layui/layui.all.js}"></script>
</head>
<body>
<div id="form-box">
    <div style="min-width:1100px;text-align: center; ">
        <!--条件查询 start-->
        <form class="layui-form">
            导入时间:
            <div class="layui-input-inline distance" style="width: 120px;">
                <input type="text" class="layui-input" id="startTime" name="startTime"
                       placeholder="请选择起始时间">
            </div>
            到
            <div class="layui-input-inline distance" style="width: 120px;">
                <input type="text" class="layui-input" id="endTime" name="endTime"
                       placeholder="请选择结束时间">
            </div>
            <button class="btn btn-primary " style="margin-left: 20px;" type="button" onclick="refresh()">查&nbsp;&nbsp;询</button>
            <button class="btn btn-success" style="margin-left: 20px;"  type="button" onclick="doExport()">导&nbsp;&nbsp;入</button>

        </form>
        <hr/>
    </div>
    <!--内容-->
    <div class="standardcontentbox">
        <!--table start-->
        <table id="table" width="100%" class="one_table" >
            <tr>
                <th style="width: 25px"></th>
                <th style="width: 500px">批次</th>
                <th style="width: 50px">已入库</th>
                <th style="width: 50px">已删除</th>
                <th style="width: 50px">总数</th>
                <th style="width: 70px">导入人</th>
                <th style="width: 70px">导入时间</th>
                <th style="width: 100px">操作</th>
            </tr>
            <tr id="rowTempalte" style="display: none">
                <td id="td0"></td>
                <td id="td1" style="text-align: left;width: 40%;padding-left: 15px"></td>
                <td id="td2"></td>
                <td id="td3"></td>
                <td id="td4"></td>
                <td id="td5"></td>
                <td id="td6"></td>
                <td id="td7" class="operate" align="center"></td>
            </tr>
        </table>
        <!--table end-->

        <div style="overflow: hidden;">
            <!--分页栏start-->
            <div id="zhuanye" style="margin-top: 10px;">
                <div id="datanumDiv">显示</div>
                <select id="rows" style="float:left;margin-top: 7px;" onchange="refresh()">
                    <option class="xialashu">10</option>
                    <option class="xialashu">20</option>
                    <option class="xialashu">50</option>
                </select>
                <div id="datatotalDiv">条记录</div>
            </div>
            <div id="pagebox" style="margin-top: 10px;">
                <ul id="pageul">
                    <li class="first" id="first" onclick="firstPage()"></li>
                    <li class="pre" id="pre" onclick="prePage()"></li>
                    <li class="pages on" id="page">1</li>
                    <li class="next" id="next" onclick="nextPage()"></li>
                    <li class="last" id="last" onclick="lastPage()"></li>
                    <li class="pages on" style="width:100px">共<span id="count"></span>条数据</li>
                </ul>
                <div style="clear:both;"></div>
            </div>
            <!--分页栏end-->
        </div>
    </div>
</div>
</body>

<script>
    function doExport() {
        var url = '/studentInput/toInputStudent';
        parent.parent.openWindow("导入文件", ['400px', '240px'], url);
    }

    /**
     * @Date: 2017/12/8
     * Description:日期id绑定渲染
     */
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#startTime' //指定元素
        });
        laydate.render({
            elem: '#endTime' //指定元素
        });
    });
    $(function () {
        queryData(10, 1);
    });

    function queryData(limit, page) {
        var postData = {
            limit: limit,
            page: page
        };
        if ($("#startTime").val() != "")
            postData.startTime = $("#startTime").val();
        if ($("#endTime").val() != "")
            postData.endTime = $("#endTime").val();
        $.ajax({
            url: "/studentInput/getStudentBatchList",
            type: "post",
            data: JSON.stringify(postData),
            dataType: "json",
            headers: {'Content-Type': 'application/json'},
            success: function (result) {
                $('#count').html(result.total);
                addRow(result.rows);
            },
            error: function (error) {
                console.log(error);
            }
        });
    }

    var oId = 1;
    function addRow(data) {
        deleteRow();
        var tr = $("#rowTempalte");
        var newTr;
        var actionHtml;
        $(data).each(function (i, element) {
            if ((parseInt(element.insertNumber) + parseInt(element.deleteNumber)) >= element.totalNumber) {
                actionHtml = '<button  style="width: 114px;height: 30px;margin-top:5px;margin-bottom:5px;cursor:auto;" class="btn btn-warning">学生入库</button>';
            } else {
                actionHtml = '<button  style="width: 114px;height: 30px;margin:5px 0px 5px 0px;" class="btn btn-success" onclick="putIn(\'' + element.id + '\',\'' + element.batchName + '\')">学生入库</button>';
            }
            newTr = tr.clone(true).attr('id', 'rowTempalte' + oId);
            newTr.css("display", "table-row");
            newTr.find("td#td0").html(i + 1);
            newTr.find("td#td1").html(element.batchName);
            newTr.find("td#td2").html(element.insertNumber);
            newTr.find("td#td3").html(element.deleteNumber);
            newTr.find("td#td4").html(element.totalNumber);
            newTr.find("td#td5").html(element.exportPerson);
            newTr.find("td#td6").html(formatDateTime(element.exportTime));
            newTr.find("td#td7").html(actionHtml);
            tr.after(newTr);
            tr = newTr;
            oId = oId + 1;
        });
    }

    //转化时间
    function formatDateTime(inputTime) {
        var date = new Date(inputTime);
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        m = m < 10 ? ('0' + m) : m;
        var d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        return y + '-' + m + '-' + d;
    }
    ;

    /**
     * @Date: 2017/12/10 0010
     * Description: 清除row
     */
    function deleteRow() {
        var length = $("#table tr").length - 2;
        for (var j = length; j > 0; j--) {
            $("#table tr:eq(" + (j + 1) + ")").remove();
        }
    }

    /**
     * @Date: 2017/12/10 0010
     * Description: 详情页面
     */
    function putIn(batchId) {
        var url = '/studentInput/toPutInStudentData?batchId=' + batchId;
        window.location.href = url;
    }

    /**
     * @Date: 2017/12/5
     * Description:分页  rows:显示条目数  page:当前第几页  count:总条目数
     */
    function nextPage() {
        if (parseInt($('#rows').val()) * ((parseInt($('#page').text())) + 1) - parseInt($('#count').text()) >= parseInt($('#rows').val())) {
            layer.msg("已到最后一页", {time: 1000});
        } else {
            $('#page').text(parseInt($('#page').text()) + 1);
            queryData($('#rows').val(), $('#page').text());
        }
    }

    function prePage() {
        if (parseInt($('#page').text()) == 1) {
            layer.msg("已到第一页", {time: 1000});
        } else {
            $('#page').text(parseInt($('#page').text()) - 1);
            queryData($('#rows').val(), $('#page').text());
        }
    }

    function firstPage() {
        if (parseInt($('#page').text()) == 1) {
            layer.msg("已到第一页", {time: 1000});
        } else {
            $('#page').text(1);
            queryData($('#rows').val(), $('#page').text());
        }
    }

    function lastPage() {
        if (parseInt($('#rows').val()) * ((parseInt($('#page').text())) + 1) - parseInt($('#count').text()) >= parseInt($('#rows').val())) {
            layer.msg("已到最后一页", {time: 1000});
        } else {
            $('#page').text(Math.ceil(parseInt($('#count').text()) / parseInt($('#rows').val())));
            queryData($('#rows').val(), $('#page').text());
        }
    }

    function refresh() {
        $('#page').text(1);
        queryData($('#rows').val(), 1);
    }

    function successClose(msg) {
        layer.close(layer.index);
        layer.msg(msg);
    }


</script>

</html>